/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.core.mgrImpl.mgrActionAssembler;

import com.inspur.edp.bef.bizentity.operation.BizMgrAction;
import com.inspur.edp.bef.dtgenerator.core.BefCoreGenCtx;
import com.inspur.edp.bef.spi.action.assembler.MgrActionAssembler;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGenerator;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier;

public class CustomMgrActionAssGenerator extends ClassGenerator {

  // region Static Members
  private static final String itemNameTemplate = "%1$sMgrActionAssembler";

  // region BasicInfos
  private BefCoreGenCtx coreGenCtx;
  private BizMgrAction action;

  public CustomMgrActionAssGenerator(BefCoreGenCtx coreGenCtx, BizMgrAction action) {
    super(coreGenCtx.getCompilationUnitInfo());
    this.coreGenCtx = coreGenCtx;
    this.action = action;
  }

  public static String getItemName(BizMgrAction action) {
    return java.lang.String.format(itemNameTemplate, action.getCode());
  }

  @Override
  protected String getName() {
    return getItemName(action);
  }

  @Override
  protected ClassGeneratorContext createClassInfoContext() {
    return new ClassGeneratorContext();
  }

  @Override
  protected java.util.ArrayList<Modifier.ModifierKeyword> getAccessModifier() {
    return new java.util.ArrayList<Modifier.ModifierKeyword>(
        java.util.Arrays.asList(
            Modifier.ModifierKeyword.PUBLIC_KEYWORD));
  }

  protected String getNameSpace() {
    return coreGenCtx.getNameSpace();
  }

  @Override
  protected TypeInfo setParentClass() {
    return new TypeInfo(MgrActionAssembler.class.getTypeName());
  }

  @Override
  protected java.util.ArrayList<ClassMethodGenerator> createMethodGenerators() {
    ArrayList<ClassMethodGenerator> list = new ArrayList<ClassMethodGenerator>();
    list.add(new MgrAssDemandPermissionGenerator(action));
    return list;
  }

  @Override
  protected java.util.ArrayList<ClassMethodGenerator> createConstructorGenerators() {
    ArrayList<ClassMethodGenerator> list = new ArrayList<ClassMethodGenerator>();
    list.add(new CustomMgrActionAssConstructorGenerator(coreGenCtx, getName(), action));
    return list;
  }
}
